<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-09
 * Time: 14:34
 */

namespace app\service;


use app\model\CardsModel;
use app\model\CardThumbModel;
use think\Exception;

/**
 * 名片点赞
 * Class CardThumbService
 * @package app\service
 */
class CardThumbService extends BaseService
{
    public $cardModel;
    public $cardThumbModel;
    public function __construct()
    {
        $this->cardModel=new CardsModel();
        $this->cardThumbModel = new CardThumbModel();
    }



    /**
     * 点赞
     * @param $add
     * @return bool|false|int
     */
    public function addThumb($add){
        try{
           return $this->cardThumbModel->insertGetId($add);
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }

    /**
     * 取消点赞
     * @param $add
     * @return bool|false|int
     */
    public function delThumb($where){
        try{
            return $this->cardThumbModel->where($where)->delete();
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }

    /**
     * 点赞信息
     * @param $where
     * @param string $field
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public function findThumb($where,$field='*')
    {
        try{
            $data = $this->cardThumbModel
                ->where($where)
                ->field($field)
                ->find();
            if($data)
                $data->toArray();
            return $data;
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }

    /**
     * 计数
     * @param $add
     * @return bool|int|string
     */
    public function queryCount($where){
        try{
            return $this->cardThumbModel->where($where)->count();
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }





}